﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using QuanLyDuAn.DTO;
using QuanLyDuAn.DataAccess;
using System.Data;
using System.Collections;

namespace QuanLyDuAn.BUS
{
    class InterviewResultController
    {
        DataSet ds;
        ArrayList list = new ArrayList();
        SqlCommand cmd;
        SqlDataAdapter da;
        SqlConnection conn;
        SqlDataReader reader;
        dbAccess database = new dbAccess();
        public  DataSet LoadInterviewResult()
        {
            conn = database.GetConnect();
            conn.Open();
            ds = new DataSet();
            cmd = new SqlCommand("getInterview_Result", conn);
            da = new SqlDataAdapter(cmd);
            da.Fill(ds, "Interview_Result");
            return ds;
        }
        public void InsertInterviewResult(String interviewer, String applicant, String result, String note)
        {
            conn = database.GetConnect();
            conn.Open();
            cmd = new SqlCommand("insertInterviewResult", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@iId", SqlDbType.VarChar).Value = interviewer;
            cmd.Parameters.Add("@aId", SqlDbType.VarChar).Value = applicant;
            cmd.Parameters.Add("@IrResult", SqlDbType.VarChar).Value = result;
            cmd.Parameters.Add("@IrNote", SqlDbType.VarChar).Value = note;
            int i = cmd.ExecuteNonQuery();
        }
        public ArrayList LoadResult()
        {
            CheckResult result;
            conn = database.GetConnect();
            conn.Open();
            cmd = new SqlCommand("getInterview_Result", conn);
            da = new SqlDataAdapter(cmd);
            reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                String interview = reader.GetString(0);
                String applicant = reader.GetString(1);
                result = new CheckResult(interview, applicant);
                list.Add(result);
            }
            return list;
        }
        public void UpdateInterviewResult(String interviewer, String applicant, String result, String note)
        {
            conn = database.GetConnect();
            conn.Open();
            cmd = new SqlCommand("updateInterviewResult", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@iId", SqlDbType.VarChar).Value = interviewer;
            cmd.Parameters.Add("@aId", SqlDbType.VarChar).Value = applicant;
            cmd.Parameters.Add("@IrResult", SqlDbType.VarChar).Value = result;
            cmd.Parameters.Add("@IrNote", SqlDbType.VarChar).Value = note;
            int i = cmd.ExecuteNonQuery();
        }
        public void DeleteInterviewResult(String applicant)
        {
            conn = database.GetConnect();
            conn.Open();
            cmd = new SqlCommand("deleteInterviewResult",conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@aId", SqlDbType.VarChar).Value = applicant;
            int i = cmd.ExecuteNonQuery();
        }
        public DataSet SearchInterviewerByResult(String result)
        {
            conn = database.GetConnect();
            conn.Open();
            ds = new DataSet();
            cmd = new SqlCommand("searchResultByIrResult", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@IrResult", SqlDbType.VarChar).Value = result;
            da = new SqlDataAdapter(cmd);
            da.Fill(ds, "Interview_Result");
            return ds;
        }
        public DataSet SearchInterviewerByApplicant(String name)
        {
            conn = database.GetConnect();
            conn.Open();
            ds = new DataSet();
            cmd = new SqlCommand("searchResultByApplicant", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@aId", SqlDbType.VarChar).Value = name;
            da = new SqlDataAdapter(cmd);
            da.Fill(ds, "Interview_Result");
            return ds;
        }
    }
     
}
